<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Jialeo\LaravelSchemaExtend\Schema;

class CreateScheduleUserChangeLogsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('schedule_user_change_logs', function (Blueprint $table) {
            $table->id();
            $table->unsignedInteger('shopId')->default(0)->comment('店铺ID');
            $table->unsignedInteger('userId')->default(0)->comment('用户ID');
            $table->unsignedInteger('date')->default(0)->comment('日期 =0，即被删除了rule');
            $table->unsignedInteger('ruleId')->default(0)->comment('旧的ruleId');
            $table->tinyInteger('type')->default(0)->comment('1修改个人排班 2修改班次管理');

            $table->json('beforeData')->nullable()->comment('变更前 schedule_users行数据');
            $table->json('afterData')->nullable()->comment('变更后 schedule_users行数据');

            $table->unsignedInteger('createdAt')->default(0)->comment('创建时间');
            $table->unsignedInteger('createdByUid')->default(0)->comment('创建人');
            $table->unsignedInteger('updatedAt')->default(0)->comment('修改时间');
            $table->unsignedInteger('updatedByUid')->default(0)->comment('修改人');
            $table->collation = 'utf8mb4_general_ci';
            $table->comment = '排班 - 用户排班变更日志';

            $table->index(['date'], 'idx_date');
            $table->index(['createdAt'], 'idx_createdAt');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('schedule_user_change_logs');
    }
}
